package counter.com.baomidou.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import counter.com.baomidou.entity.Fileinfo;
import counter.com.baomidou.entity.Serverinfo;
import counter.com.baomidou.service.IFileinfoService;
import counter.com.common.Result;
import counter.com.connproperty.fileinfo.FileInfoSearchProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-10-02
 */
@RestController
@RequestMapping("/fileinfo")
public class FileinfoController {
    @Autowired
    IFileinfoService fileinfoService;

    @PostMapping("/search")
    public Result search(@RequestBody FileInfoSearchProperty data) {
        LambdaQueryWrapper<Fileinfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(true, Fileinfo::getId);

        if (!data.getName().equals("")) {
            wrapper.eq(Fileinfo::getName, data.getName());
        }
        if (!data.getIp().equals("")) {
            wrapper.eq(Fileinfo::getIp, data.getIp());
        }
        wrapper.eq(Fileinfo::getType, data.getType());
        Page page = new Page(data.getPage(), data.getPagesize());
        IPage iPage = fileinfoService.page(page, wrapper);
        return Result.success(iPage);
    }
}
